package collection;

import java.util.ArrayList;
import java.util.List;

public class ListDemo3 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++){
            list.add(i*10);
        }
        System.out.println("list:"+list);

        List<Integer> sublist = list.subList(2,6);//获取集合中下标为2到6的子集
        System.out.println("sublist:"+sublist);


        for (int i = 0;i<sublist.size();i++){
            sublist.set(i,sublist.get(i)*10);//将子集元素扩大十倍
        }
        System.out.println("sublist"+sublist);
        //对子集的操作就是对原集合的操作
        System.out.println("list:"+list);


        list.set(3,100000);//将原集合中下标为3的元素设置为100000
        System.out.println("list:"+list);
        //原集合改变了，子集跟着一起改变
        System.out.println("sublist:"+sublist);



        list.remove(4);
        System.out.println("list:"+list);
        //System.out.println("sublist:"+sublist);//原集合长度改变后，子集将不能再进行任何改变，若操作则发生异常，但是可以重新获取子集

































































    }
}
